#!/bin/bash
## Nova计算节点安装配置

# http://www.cnblogs.com/elvi/p/7738165.html

# computer1 安装配置

#安装Nova
yum install -y openstack-nova-compute
#安装Neutron
yum install -y openstack-neutron-linuxbridge ebtables ipset

########################################
#备份默认配置
cp /etc/nova/nova.conf{,.bak}
cp /etc/neutron/neutron.conf{,.bak}
cp /etc/neutron/plugins/ml2/linuxbridge_agent.ini{,bak}

#设置Nova实例路径(磁盘镜像文件)
Vdir=/data/nova
VHD=$Vdir/instances
mkdir -p $VHD
chown -R nova:nova $Vdir

#Netname=eth1  #网卡名
read -p "input ethernet name:" Netname
if [ -z $Netname ]
then
  Netname=eth1
fi

IP=`ifconfig $Netname | grep 'inet' | grep -v 'inet6' | cut -d: -f2 | awk '{ print $2}'`
echo $Netname
echo $IP


#使用QEMU或KVM ,KVM硬件加速需要硬件支持,虚拟机使用 qemu
[[ `egrep -c '(vmx|svm)' /proc/cpuinfo` = 0 ]] && { Kvm=qemu; } || { Kvm=kvm; }
echo "使用 $Kvm"

VncProxy=192.168.100.99 #VNC代理地址vip

# #nova配置
#egrep -v '^$|#' /etc/nova/nova.conf
echo '#
[DEFAULT]
instances_path='$VHD'
enabled_apis = osapi_compute,metadata
transport_url = rabbit://openstack:openstack@controller:5673
my_ip = '$IP'
use_neutron = True
firewall_driver = nova.virt.firewall.NoopFirewallDriver
cpu_allocation_ratio = 4

[api_database]
connection = mysql+pymysql://nova:nova@controller/nova_api
[database]
connection = mysql+pymysql://nova:nova@controller/nova

[api]
auth_strategy = keystone
[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller:11211
auth_type = password
project_domain_name = default
user_domain_name = default
project_name = service
username = nova
password = nova

[vnc]
enabled = true
vncserver_listen = 0.0.0.0
vncserver_proxyclient_address = $my_ip
novncproxy_base_url = http://'$VncProxy':6080/vnc_auto.html
[glance]
api_servers = http://controller:9292
[oslo_concurrency]
lock_path = /var/lib/nova/tmp

[placement]
os_region_name = RegionOne
project_domain_name = Default
project_name = service
auth_type = password
user_domain_name = Default
auth_url = http://controller:35357/v3
username = placement
password = placement

[libvirt]
virt_type = '$Kvm'
cpu_mode = host-passthrough

[neutron]
url = http://controller:9696
auth_url = http://controller:35357
auth_type = password
project_domain_name = default
user_domain_name = default
region_name = RegionOne
project_name = service
username = neutron
password = neutron
#'>/etc/nova/nova.conf

#-----------------------------------------
#neutron配置
echo '#
[DEFAULT]
auth_strategy = keystone
transport_url = rabbit://openstack:openstack@controller:5673

[keystone_authtoken]
auth_uri = http://controller:5000
auth_url = http://controller:35357
memcached_servers = controller1:11211,controller2:11211,controller3:11211
auth_type = password
project_domain_id = default
user_domain_id = default
project_name = service
username = neutron
password = neutron

[oslo_concurrency]
lock_path = /var/lib/neutron/tmp
#'>/etc/neutron/neutron.conf
#
# provider:网卡名
echo '
[linux_bridge]
physical_interface_mappings = provider:eth1
[securitygroup]
enable_security_group = true
firewall_driver = neutron.agent.linux.iptables_firewall.IptablesFirewallDriver
[vxlan]
enable_vxlan = false
# local_ip = 10.2.1.21
# l2_population = true
#'>/etc/neutron/plugins/ml2/linuxbridge_agent.ini

#启动
systemctl enable libvirtd.service openstack-nova-compute.service neutron-linuxbridge-agent.service
systemctl restart libvirtd.service openstack-nova-compute.service neutron-linuxbridge-agent.service
#
nova-manage cell_v2 discover_hosts
openstack compute service list

# CPU倍数
#cpu_allocation_ratio=4.0